package demo1;


class Money implements Cloneable{
    public double Money = 89293.6;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Person implements Cloneable{
    public int id;
    public Money m = new Money();

    public Person(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Person{" +
                "id=" + id +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person personCopy = (Person) super.clone();
        personCopy.m = (Money) this.m.clone();
        return personCopy;
    }
    /*@Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }*/
}

public class TestDemo3 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Person person = new Person(67);
        System.out.println(person);

        Person person2 =(Person)person.clone();
        System.out.println(person2);

        System.out.println("修改一下MONEY：");
        person2.m.Money = 29343.44;
        System.out.println(person.m.Money);
        System.out.println(person2.m.Money);

        /*System.out.println("修改一下ID：");
        person2.id = 34;
        System.out.println(person.id);
        System.out.println(person2.id);*/
    }
}
